package com.ywt.cda.test;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import com.alibaba.fastjson.JSONObject;
import com.ywt.cda.action.model.PortsModel;
import com.ywt.cda.action.model.ShopCompanyModel;
import com.ywt.cda.action.vo.ShopCompanyVo;
import com.ywt.cda.core.dao.page.Page;
import com.ywt.cda.domain.Ana2ndData;
import com.ywt.cda.domain.AnaImportData;
import com.ywt.cda.domain.enums.DimensionFlag;
import com.ywt.cda.domain.enums.OrderByEnum;
import com.ywt.cda.service.GovAnalysisService;
import com.ywt.cda.service.ParamValidateService;
import com.ywt.cda.service.PortService;
import com.ywt.cda.service.ShopCompanyOrientedService;
import com.ywt.cda.service.ShopCompanyService;
import com.ywt.cda.utils.DateUtils;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration({
		"classpath:conf/spring/web/*.xml", "classpath:conf/spring/*.xml"
})
@ActiveProfiles("test")
public class BaseTestCase {
	@Resource 
	GovAnalysisService govAnalysisService;
	@Resource
	PortService portService;
	@Resource
	ShopCompanyOrientedService shopCompanyOrientedService;
	@Resource
	ShopCompanyService shopCompanyService;
	@Resource
	private ParamValidateService paramValidateService;
	@Test
	public void test() {
		// List<Ana2ndData> datas=govAnalysisService.queryTotalData("2016-02", "2016-03", AnaTable.TB_ANA_DATA_2ND_GOV_M, null, DimensionFlag.SHOPS_COMPANY);
		PortsModel portsModel = new PortsModel();
		Date date = new Date();
		String today = DateUtils.format(date, "yyyy-MM-dd");
		portsModel.setStartTime_F(DateUtils.getSpecifiedDayBefore(today, 6));
		portsModel.setEndTime_F(today);
		portsModel.setCityOrPort("CITY");

		List<Ana2ndData> datas = portService.getExportData(portsModel);
		JSONObject result = new JSONObject();

		portService.toJson(datas, result, portsModel);
		System.out.println(datas);
		System.out.println(result.toJSONString());
	}

	@Test
	public void testShops() {
		JSONObject object = new JSONObject();
		shopCompanyOrientedService.setJsonShops(object, "王");
		System.out.println(object.toJSONString());
	}

	@Test
	public void testShopData() {
		// 默认查近七天
		ShopCompanyModel shopCompanyModel = new ShopCompanyModel();
		Date date = new Date();
		String today = DateUtils.format(date, "yyyy-MM-dd");
		shopCompanyModel
				.setStartTime(DateUtils.getSpecifiedDayBefore(today, 7));
		shopCompanyModel.setEndTime(today);
		if (!paramValidateService.validate(shopCompanyModel)) {
			return ;
		}
		List<AnaImportData> datas = shopCompanyService.getTopNShopImportData(
				shopCompanyModel, 5, OrderByEnum.SUM_NUM);

		List<ShopCompanyVo> vos = shopCompanyOrientedService.toVo(datas);

		// 5家企业的折线图-按票数

		List<AnaImportData> shopDatas = shopCompanyOrientedService.getShopData(
				shopCompanyModel, vos);

		JSONObject objectZhexian = new JSONObject();

		shopCompanyOrientedService.toZhexianJson(objectZhexian, shopDatas,
				shopCompanyModel,vos, OrderByEnum.SUM_NUM);
		
		List<Ana2ndData> pieDatas= shopCompanyOrientedService.getDatas(shopCompanyModel,vos,DimensionFlag.S_CATEGORY,new Page(1,10));
		
		List<Ana2ndData> mapDatas=shopCompanyOrientedService.getDatas(shopCompanyModel,vos,DimensionFlag.PROVINCE_TYPE,null);
		
//		List<Ana2ndData> nianDatas=shopCompanyOrientedService.getDatas(shopCompanyModel,vos,DimensionFlag.S_CATEGORY);
		JSONObject objectOtherGraph=new JSONObject();
		shopCompanyOrientedService.toOtherGraphJson(objectOtherGraph,pieDatas,mapDatas,null,vos);
		System.out.println(objectZhexian);
	}
}
